package br.edu.frb.lista;

/**
 * @author Junior
 * @author joelamalio
 */
public abstract class ListaDuplamenteEncadeadaAb<T> {

    //<editor-fold defaultstate="collapsed" desc="Node (Inner Class)">
    protected class Node<T> {

        //<editor-fold defaultstate="collapsed" desc="Atributos">
        private T valor;
        private Node proximo;
        private Node anterior;
        //</editor-fold>

        //<editor-fold defaultstate="collapsed" desc="Contrutores">
        public Node(T valor) {
            this.valor = valor;
        }

        protected Node(T valor, Node proximo, Node anterior) {
            this.valor = valor;
            this.proximo = proximo;
            this.anterior = anterior;
        }

        protected Node(Node<T> node) {
            if (node != null) {
                this.valor = node.valor;
                this.proximo = node.proximo;
                this.anterior = node.anterior;
            }
        }
        //</editor-fold>

        //<editor-fold defaultstate="collapsed" desc="Get">
        protected Node getProximo() {
            return proximo;
        }

        protected Node getAnterior() {
            return anterior;
        }

        protected T getValor() {
            return valor;
        }
        //</editor-fold>

        //<editor-fold defaultstate="collapsed" desc="Set">
        protected void setProximo(Node proximo) {
            this.proximo = proximo;
        }

        protected void setAnterior(Node anterior) {
            this.anterior = anterior;
        }

        protected void setValor(T valor) {
            this.valor = valor;
        }
        //</editor-fold>

        //<editor-fold defaultstate="collapsed" desc="Override">
        @Override
        protected Object clone() throws CloneNotSupportedException {
            return new Node<T>(this);
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Node<T> other = (Node<T>) obj;
            if (this.valor != other.valor && (this.valor == null || !this.valor.equals(other.valor))) {
                return false;
            }
            return true;
        }

        @Override
        public int hashCode() {
            int hash = 7;
            hash = 47 * hash + (this.valor != null ? this.valor.hashCode() : 0);
            return hash;
        }

        @Override
        public String toString() {
            return valor.toString();
        }
        //</editor-fold>
    }
    //</editor-fold>
}
